import configparser
import platform
import os

os_name = platform.system()
conf = configparser.ConfigParser()
config_dir = os.path.dirname(os.path.abspath(__file__))
conf.read(os.path.join(config_dir, 'config.ini'))
conf.set("project", "base_dir", config_dir)

if os_name == 'windows':
    for k, v in conf.items('windows_dir'):
        conf.set('dir', k, v)
else:
    for k, v in conf.items('linux_dir'):
        conf.set('dir', k, v)
    if __name__ == '__main__':
        sections = conf.sections()
        print('获取配置文件所有的section', sections)

        options = conf.options('dir')
        print('获取指定section下所有option', options)

        items = conf.items('dir')
        print('获取指定section下所有的键值对', items)

        value = conf.get('dir', 'source_data_dir')
        print('获取指定的section下的option', type(value), value)

        value = conf.get('gpu', 'device_id')
        print('获取指定的section下的option', type(value), value)

        value = conf.get('project', 'base_dir')
        print('获取指定的section下的option', type(value), value)
